<%@ page contentType="text/html; charset=utf-8" language="java"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>修改密码</title>
<style type="text/css">
html,body {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
}
</style>
<script src="scripts/boot.js" type="text/javascript"></script>
</head>
<body>
	<div class="mini-fit">
		<div class="mini-panel" title="header" iconCls="icon-add" borderStyle="border:0px" style="width:100%;height:100%;" showHeader="false" showToolbar="false" showCloseButton="false" showFooter="true">
			<!--footer-->
			<div property="footer" style="text-align:center;padding:5px">
				<a class="mini-button" plain="true" iconCls="icon-ok" onclick="save">提交</a>
				&nbsp;&nbsp; 
				<a class="mini-button" plain="true" iconCls="icon-remove" onclick="closeWindow()">取消</a>
			</div>
			<div id="form1">
				<div>
					<fieldset style="border:solid 1px #aaa;padding:10px;">
						<legend style="margin-left:20px">
							<span>新密码信息</span>
						</legend>
						<table width="100%" style="margin:0 auto;">
							<tr>
								<td>
									<table>
										<tr>
											<td width="100px" align="right">原密码：</td>
											<td><input id="oldpassword" name="oldpassword" onenter="enteroldpassword" required="true" vtype="/^[A-Za-z0-9]+$/" class="mini-password" style="width:170px;"/></td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</fieldset>
					<fieldset style="border:solid 1px #aaa;padding:10px;">
						<legend style="margin-left:20px">
							<span>修改密码</span>
						</legend>
						<table width="100%" style="margin:0 auto;">
							<tr>
								<td>
									<table>
										<tr>
											<td width="100px" align="right">新密码：</td>
											<td><input id="password" name="password" onenter="enterpassword" required="true" class="mini-password" style="width:170px;"/></td>
										</tr>
										<tr>
											<td width="100px" align="right">确认密码：</td>
											<td><input id="repassword" name="repassword" onenter="save" required="true" class="mini-password" style="width:170px;"/></td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</fieldset>
				</div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		mini.parse();
		
		mini.get("oldpassword").focus();
		
		function enteroldpassword () {
			mini.get("password").focus();
		}
		
		function enterpassword () {
			mini.get("repassword").focus();
		}
		
		function save() {
			var form = new mini.Form("#form1");
			form.validate();
			if (form.isValid() == false)
				return;
			
			var data = form.getData();
			var oldpassword = data.oldpassword;
			var password = data.password;
			var repassword = data.repassword;
			
			var reg = /^(?![^a-zA-Z]+$)(?!\D+$).{6,15}$/;
			if (!reg.test(password)) {
			    mini.showMessageBox({
					title: "提示",
					width: 300,   
				    buttons: ["ok"],
				    iconCls: "mini-messagebox-warning",
				    message: "新密码必须为6-15位的数字和字母的组合！"
				});
			    return null;
			}

			if (oldpassword == password) {
				mini.showMessageBox({
					title: "提示",
					width: 250,   
				    buttons: ["ok"],    
				    iconCls: "mini-messagebox-warning",
				    message: "新密码与原密码输入一致！"
				});
				return null;
			}
			
			if (password != repassword) {
				mini.showMessageBox({
					title: "提示",
					width: 250,   
				    buttons: ["ok"],    
				    iconCls: "mini-messagebox-warning",
				    message: "两次密码输入不一致！"
				});
				return null;
			}
			
			$.ajax({
				url : "passwordUpdate",
				type : "post",
				data : {
					oldpassword : oldpassword,
					password : password,
					repassword : repassword
				},
				success : function (result) {
					var getResult = mini.decode(result);
					if (getResult.res) {
						mini.showMessageBox({
							title: "提示",
							width: 250,   
						    buttons: ["ok"],    
						    iconCls: "mini-messagebox-warning",
						    message: "修改密码成功，请重新登陆！",
						    callback: function (action) {
						    	top.location.href = "logout";
						    }
						});
					} else {
						mini.showMessageBox({
							title: "提示",
							width: 250,   
						    buttons: ["ok"],    
						    iconCls: "mini-messagebox-warning",
						    message: getResult.msg
						});
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					mini.showMessageBox({
					    title: "错误",
						width: 250,   
					    buttons: ["ok"],    
					    iconCls: "mini-messagebox-error",
					    message: jqXHR.responseText
					});
				}
			});
		}
		
		function closeWindow(action) {
			if (window.CloseOwnerWindow)
				return window.CloseOwnerWindow(action);
			else
				window.close();
		}
		
		function cancel(e) {
			closeWindow(e);
		}
	</script>
</body>
</html>
